<?php

namespace app\admin\model;
use think\Db;
use think\Model;
use think\Request;

class AdminUser extends Model
{
    public $table = 'ent_admin_user';
    protected  $autoWriteTimestamp=true;
    /**
     * 查询所有的数据
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getSelect()
    {
     $admin =  Db::table($this->table)->select();
     return $admin;
    }

    /**
     * 删除单条数据
     * @param $id
     * @return int
     */
    public function getDel($id)
    {
        $admin = Db::table($this->table)->delete($id);
        return $admin;
    }

    public function getUpdateFind($id)
    {
        $admin = Db::table($this->table)->where(['id'=>$id])->find();
        return $admin;
    }

    public function getUp($id,$data)
    {

        $data['update_time'] = time();
        $admin = Db::table($this->table)->where(['id'=>$id])->update($data);
        return $admin;
    }

    public function getCreate($data)
    {

      $data['password'] = md5($data['password']);
      $data['last_login_ip'] = Request::instance()->ip();

      $res = $this->data($data)->allowField(true) ->save();


     return $res;
    }

    public function getFiled($data)
    {


        $admin = Db::table($this->table)->where(['username'=>$data['username']])->find();

        if (!empty($admin))
        {
            if ($admin['password'] != md5($data['password']))
            {
                return null;
            }

            return 1;
        }else{
            return null;
        }
    }
}
